﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Extensibility;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Syntax;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Reporting;
using YasharEl.Infrastructure.ApplicationModel.Bootstrap.Execution;
using System.Diagnostics.Contracts;

namespace YasharEl.Infrastructure.ApplicationModel.Bootstrap
{
    /// <summary>
    /// The executor is responsible for executing a given syntax on the extensions.
    /// </summary>
    /// <typeparam name="TExtension">The type of the extension.</typeparam>
    [ContractClass(typeof(ExecutorContract<>))]
    public interface IExecutor<TExtension> : IDescribable
        where TExtension : IBootstrappingExtension
    {
        /// <summary>
        /// Executes the specified syntax on the extensions.
        /// </summary>
        /// <param name="syntax">The syntax.</param>
        /// <param name="extensions">The extensions.</param>
        /// <param name="executionContext">The execution context which is used for reporting</param>
        void Execute(ISyntax<TExtension> syntax, IEnumerable<TExtension> extensions, IExecutionContext executionContext);
    }

    [ContractClassFor(typeof(IExecutor<>))]
    internal abstract class ExecutorContract<TExtension> : IExecutor<TExtension>
        where TExtension : IBootstrappingExtension
    {
        public void Execute(ISyntax<TExtension> syntax, IEnumerable<TExtension> extensions, IExecutionContext executionContext)
        {
            Contract.Requires<ArgumentNullException>(syntax != null, "syntax could not be null.");
            Contract.Requires<ArgumentNullException>(executionContext != null, "executionContext could not be null.");
        }

        public string Name
        {
            get { return default(string); }
        }

        public string Describe()
        {
            return default(string);
        }
    }
}
